package com.dbh.alg.algorithm.hot100.哈希;

import java.util.*;

/**
 * @author 董帮辉
 * @date 2025/7/12
 **/
public class Leetcode49_字母异位词分组 {

    public List<List<String>> groupAnagram(String[] strs) {
        if (strs.length == 0) {
            return new ArrayList<>();
        }
        Map<String, List<String>> map = new HashMap<>();
        for (String s : strs) {
            char[] ca = s.toCharArray();
            Arrays.sort(ca);
            String key = String.valueOf(ca);
            if (!map.containsKey(key)) {
                map.put(key, new ArrayList<>());
            }
            map.get(key).add(s);
        }
        return new ArrayList<>(map.values());
    }
}
